import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {ScheduleListPage} from "../schedule/schedule-list/schedule-list";
import {ClientNoteListPage} from "../client/client-note/client-note-list/client-note-list";
import {PushService} from '../../services/native/push/push.service';
import { UnlockService } from '../../services/native/authentication/authentication.service';
import {ClientVipInterestsPage} from "../client/client-vip/client-vip-interests/client-vip-interests";
import {PolicyListPage} from "../policy/policy-list/policy-list";
import {InformationListPage} from "../information/information-list/information-list";
import {ClientPolicyListPage} from "../client/client-policy-list/client-policy-list";
import {WebcastFavoriteListPage} from "../webcast/webcast-favorite-list/webcast-favorite-list";
import {PersonalGroupPerformancePage} from "../performance/personal-group-performance/personal-performance";


@IonicPage()
@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {

    public from: string;
    public from_id: number;

    constructor(public navCtrl: NavController,
                public navParams: NavParams,
                private pushService: PushService,
                private unlockService: UnlockService) {
        this.from = this.navParams.get('from');
        this.from_id = this.navParams.get('from_id');
    }

    ionViewDidLoad() {
    }

    openThemeableBrowser(){

    }

    //todo 复杂跳转
    goDetailOrBack(id: number): void {
        if (!this.from) {
            this.navCtrl.push('DetailPage', {'id': id})
        } else {
            //先请求后台发生关联，然后退回到之前页面
            this.navCtrl.pop().then(() => {
                this.navCtrl.setPages([{page: 'AboutDetailPage', params: {'id': this.from_id, 'u_id': id}}]);
            });
            //this.navCtrl.push(this.from);//这种情况不能用push
        }
    }

    goToScheduleList() {
        this.navCtrl.push('ScheduleListPage');
    }

    // 进入日程添加
    goToScheduleAdd() {
        this.navCtrl.push('ScheduleAddPage');
    }

    // 进入笔记列表添加
    goToClientNoteList() {
        this.navCtrl.push('ClientNoteListPage');
    }

    // 进入客户详情
    goToClientDetail() {
        this.navCtrl.push('ClientDetailPage');
    }

    //进入vip权益
    goToClientVipInterests() {
        this.navCtrl.push('ClientVipInterestsPage');
    }

    // 进入添加准客户
    goToAddNewCust() {
        this.navCtrl.push('ClientsAddPage');
    }

    logout() {
        // localStorage.clear();
        // sessionStorage.clear();
        // location.hash = '#/login';
        this.unlockService.lockout();
    }

    // 跳转到编辑扩展字段
    goToEditExtension() {
        this.navCtrl.push('ExtensionEidtPage');
    }

    // 跳转到筛选客户
    goToClientFilter() {
        this.navCtrl.push('ClientFilterPage');
    }

    // 跳转到活动详情
    goToActivityDetail() {
        this.navCtrl.push('ActivitDetailPage');
    }

    goToActivityList() {
        this.navCtrl.push('ActivityListPage');
    }

    goToRosterFilter() {
        this.navCtrl.push('RosterFilterPage');
    }

    // 添加笔记
    goTONote() {
        this.navCtrl.push('ClientNoteListPage')
    }

    // 保单
    goToPolicy(){
        this.navCtrl.push('PolicyListPage')
    }

    goToWebcastFavorite() {
        this.navCtrl.push('WebcastFavoriteListPage');
    }

    goToInformation() {
        this.navCtrl.push('InformationListPage');
    }

    goToMessage() {
        this.navCtrl.push('MessageOverviewPage');
    }

    goClientPolicy() {
        this.navCtrl.push('ClientPolicyListPage')
    }

    goRenewalDetail() {
        this.navCtrl.push('HistoricalPerformancePage')

    }

    goPersonalPerformancePage() {
        this.navCtrl.push('PersonalGroupPerformancePage', {
            type: 1
        })
    }

    goGroupPerformancePage() {
        this.navCtrl.push('PersonalGroupPerformancePage',
            {
                type: 2
            })
    }

    goPersonalPerformanceListPage() {
        this.navCtrl.push('PersonalPerformanceListPage')
    }

    goGroupPerformanceListPage() {
        this.navCtrl.push('GroupPerformanceListPage')
    }
}
